#ifndef NETWORK_H
#define NETWORK_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#include "stream.h"

#define PACKET_BUFFER_MAX_SIZE 1400

struct Socket
{
	int32_t fileDescriptor;
	struct sockaddr_in address;
};

struct Packet
{
	char buffer[PACKET_BUFFER_MAX_SIZE];
	size_t size;
};

struct Address
{
	uint32_t address;
	uint16_t port;
};

int createSocketUDP(struct Socket * socket, uint16_t port);

int bindSocket(struct Socket * socket);

void closeSocket(struct Socket * socket);

void setSocketNonBlocking(struct Socket * socket);



int broadcastPacket(struct Socket * socket, struct Packet * packet, uint16_t port);

int sendPacket(struct Socket * socket, struct Packet * packet, struct Address * address);

int receivePacket(struct Socket * socket, struct Packet * packet, struct Address * address);



int sendStream(struct Socket * socket, struct Stream * stream, struct Address * address);

int receiveStream(struct Socket * socket, struct Stream * stream, struct Address * address);




int setAddress(struct Address * address, const char * addressString, uint16_t port);

void setAddressFromSocket(struct Address * address, struct Socket * socket);

void printAddress(struct Address * address);

int compareAddress(struct Address * address1, struct Address * address2);


#endif

